<template>
    <el-row :gutter="20" id="app" style="padding:20px;">
		<el-row>
			<el-col :span="24">
				<el-input placeholder="请输入分店名称" v-model="name" class="mt mb" size="mini">
					<template slot="prepend">分店名称</template>
				</el-input>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="24">
				<el-input placeholder="请输入当前分店的联系方式" v-model="phone" class="mt mb" size="mini">
					<template slot="prepend">联系方式</template>
				</el-input>
			</el-col>
		</el-row>
		<el-row class="width mt mb">
			<el-col :span="24">
				<el-cascader v-model="sele" :options="area" change-on-select class="width mt mb" size="mini"></el-cascader>
				<el-input type="textarea" placeholder="请输入区域详细地址" v-model="address" size="mini"></el-input>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="12">
				<el-button @click.native="close" style="width:90%;display:block;" size="mini">取消</el-button>
			</el-col>
			<el-col :span="12">
				<el-button type="success" @click.native="submit" style="width:90%;display:block;" :loading="loading" size="mini">确定</el-button>
			</el-col>
		</el-row>
	</el-row>
</template>
<script>
import C from '@/common/common.js'
import address from '@/service/organization/address.js'
export default {
  name: 'addShop',
  data () {
    return {
      id: 0,
      name: '',
      phone: '',
      address: '',
      area: [],
      sele: []
    }
  },
  async mounted () {
    this.area = address
    let RequestUrl = C.getDatas()
    if (RequestUrl.row) {
      let row = RequestUrl.row
      this.id = row.id
      this.name = row.name
      this.phone = row.phone
      this.address = row.address
      this.sele = [row.province, row.city, row.area]
    }
  },
  methods: {
    async submit (index) {
      if (this.name == '') {
        C.error('请填写分店名称')
        return false
      } else if (this.phone == '') {
        C.error('请输入分店联系方式')
        return false
      } else if (this.sele.length != 3) {
        C.error('请选择分店所在区域')
        return false
      } else if (this.address == '') {
        C.error('请填写分店所在区域的详细地址')
        return false
      }
      let data = {
        name: this.name,
        phone: this.phone,
        address: this.address,
        province: this.sele[0],
        city: this.sele[1],
        area: this.sele[2]
      }
      let url = ''
      let RequestUrl = C.getDatas()
      if (RequestUrl.row) {
        data.id = this.id
        url = '/organization/shop/editshop'
      } else url = '/organization/shop/addshop'
      this.loading = true
      let res = await C.ajax(url, data, 'post')
      this.loading = false
      if (res) {
        C.closeBrowserWindow(res)
      }
    },
    close () {
      C.closeBrowserWindow()
    }
  }
}
</script>
<style>
.mb {
  margin-bottom: 20px;
}
</style>
